package com.plian.system.dao.fr.enterprise;

import com.plian.Tools.pagedata.PageData;
import com.plian.system.dao.DaoSupport;
import com.plian.system.model.page.Page;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Component
public class EnterpriseDao {
    @Resource(name = "daoSupport")
    private DaoSupport dao;

    /**
     * 保存
     * @param pd
     * @throws Exception
     */
    public void save(PageData pd) throws Exception {
        dao.save("EnterpriseMapper.save",pd);
    }

    /**
     * 修改
     * @param pd
     * @throws Exception
     */
    public void edit(PageData pd) throws Exception {
        dao.update("EnterpriseMapper.edit",pd);
    }

    /**
     * 修改删除状态
     * @param ids
     * @throws Exception
     */
    public void edit_del_ids(List<String> ids) throws Exception {
        dao.update("EnterpriseMapper.edit_del_ids",ids);
    }

    /**
     * 分页查询
     * @param page
     * @return
     * @throws Exception
     */
    public List<PageData> listPage(Page page) throws Exception {
        return (List<PageData>) dao.findForList("EnterpriseMapper.listPage",page);
    }
    public List<PageData> reportList(Page page) throws Exception {
        return (List<PageData>) dao.findForList("EnterpriseMapper.reportList",page);
    }

    /**
     * 根据id批量查询
     * @param pageData
     * @return
     * @throws Exception
     */
    public List<PageData> findbyIds(PageData pageData) throws Exception {
        List<PageData> lista = (List<PageData>) dao.findForList("EnterpriseMapper.ogrId_name", pageData);
        HashMap<String, String> map = new HashMap<>();
        List<PageData> listb = (List<PageData>) dao.findForList("EnterpriseMapper.findbyIds", pageData);
        List<PageData> listc = new ArrayList<>();
        for (PageData pd:lista){
            String orgId = pd.getString("orgId");
            String orgName = pd.getString("orgName");
            map.put(orgId,orgName);
        }
        for (PageData pd:listb){
            String orgId = pd.getString("orgId");
            String s = map.get(orgId);
            pd.put("orgName",s);
            listc.add(pd);
        }
        return listc;
    }

    /**
     * 根据id批量查询
     * @param pageData
     * @return
     * @throws Exception
     */
    public List<PageData> findByOrgIds(PageData pageData) throws Exception {
        return (List<PageData>) dao.findForList("EnterpriseMapper.findByOrgIds",pageData);
    }

    /**
     * 根据id批量查询
     * @param pageData
     * @return
     * @throws Exception
     */
    public List<PageData> selectDistinct(PageData pageData) throws Exception {
        return (List<PageData>) dao.findForList("EnterpriseMapper.selectDistinct",pageData);
    }

    /**
     * 根据id查询数据
     * @param id
     * @return
     * @throws Exception
     */
    public PageData findbyId(String id) throws Exception {
        return (PageData) dao.findForObject("EnterpriseMapper.findbyId",id);
    }
    /**
     * 根据id查询数据
     * @param orgId
     * @return
     * @throws Exception
     */
    public PageData findbyOrg(String orgId) throws Exception {
        return (PageData) dao.findForObject("EnterpriseMapper.findbyOrg",orgId);
    }
    /**
     * 批量修改状态
     * @param pd 下id为string集合
     * @throws Exception
     */
    public void  refer(PageData pd) throws Exception {
        dao.update("EnterpriseMapper.refer",pd);
    }

    /**
     * 获取所有带简称带数据
     * @return
     * @throws Exception
     */
    public List<PageData> getAllUnitCheckName() throws Exception {
        return (List<PageData>) dao.findForList("EnterpriseMapper.getAllUnitCheckName", null);
    }

}
